
var ipp = require('ipp');
const fs = require('fs');
var printer = ipp.Printer('http://BRN001BA95AD077.local.:631', {
    version: '1.0'
});

var JsBarcode = require('jsbarcode');
var Canvas = require("canvas");

// var canvas = new Canvas();
// JsBarcode(canvas, "CS111110000");

// const out = fs.createWriteStream(process.cwd() + '/test.png');
// const stream = canvas.createPNGStream()
// stream.pipe(out)
// // const buf2 = canvas.toBuffer()

const bwipjs = require('bwip-js');

bwipjs.toBuffer({
    bcid: 'code128',       // Barcode type
    text: '0123456789',    // Text to encode
    scale: 3,               // 3x scaling factor
    height: 10,              // Bar height, in millimeters
    includetext: true,            // Show human-readable text
    textxalign: 'center',        // Always good to set this
}, function (err, png) {
    if (err) {
        // Decide how to handle the error
        // `err` may be a string or Error object
    } else {
        var msg = {
            "operation-attributes-tag": {
                "requesting-user-name": "admin",
                "job-name": "My Test Job",
                "document-format": "application/octet-stream"
            },
            data: new Buffer('')
        };

        printer.execute("Print-Job", msg, function (err, res) {
            console.log(err);
            console.log(res);
        });
        // `png` is a Buffer
        // png.length           : PNG file length
        // png.readUInt32BE(16) : PNG image width
        // png.readUInt32BE(20) : PNG image height
    }
});

// fs.readFile(process.cwd() + '/test.png', function(err, buf) {
//     console.log(buf)
//     var msg = {
//         "operation-attributes-tag": {
//             "requesting-user-name": "admin",
//             "job-name": "My Test Job",
//             "document-format": "application/octet-stream"
//         },
//         data: buf
//     };

//     printer.execute("Print-Job", msg, function(err, res) {
//         console.log(err);
//         console.log(res);
//     });

// });
// printer.execute('Get-Printer-Attributes', null, function (err, res) {
//     console.log(res);
// });

// var ipp = require('./../ipp');
var PDFDocument = require('pdfkit');
var concat = require("concat-stream");

// var doc = new PDFDocument({ margin: 0 });
// doc.text(".", 0, 0);


// doc.pipe(concat(function (data) {
//     var printer = ipp.Printer("http://BRN001BA95AD077.local.:631", {
//         version: '1.0'
//     });
//     var msg = {
//         "operation-attributes-tag": {
//             "requesting-user-name": "Bumblebee",
//             "job-name": "whatever.pdf",
//             // "document-format": "application/pdf"
//         },
//         "job-attributes-tag": {
//             "media-col": {
//                 "media-source": "tray-2"
//             }
//         }
//         , data: data
//     };
//     printer.execute("Print-Job", msg, function (err, res) {
//         console.log(err);
//         console.log(res);
//     });
// }));
// doc.end();